﻿using Colorful.CMS.Core;
using Colorful.Models;
using Colorful.Database;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Colorful.CMS.Controllers
{
    public class ArticleController : BaseController
    {
        [Route("/article/{id}")]
        [Route("/article/preview")]
        public IActionResult ViewArticle(string id, string title, string intro, string content)
        {
            Article article = null;
            if (string.IsNullOrEmpty(id))
            {
                article = new Article()
                {
                    Title = title,
                    Intro = intro,
                    Content = content
                };
            }
            else
            {
                using (var db = CMSDbHelper.GetDb())
                {
                    article = db.Articles.FirstOrDefault(a => a.Id == id);
                }
            }
            return View(article);
        }
    }
}
